package com.ideal.frame.util;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author: jin
 * @CreateTime: 2019-11-08 13:17
 * @Description: 字符串工具类
 */
public class StringUtil {

    /**
     * @Title: getPropertyByColumn
     * @Description: 根据字段名转换为Java类中的属性名
     * @param @param column
     * @param @return    设定文件
     * @return String    返回类型
     * @throws
     */
    public static String getPropertyByColumn(String column) {
        column = column.toLowerCase();
        if (column.contains("_")) {
            String[] array = column.split("_");
            StringBuffer sb = new StringBuffer();
            sb.append(array[0]);
            for (int i = 1; i < array.length; i++) {
                sb.append(toUpperCaseFirstOne(array[i]));
            }
            return sb.toString();
        }
        return column;
    }

    /**
     * 首字母转大写
     * @param s
     * @return
     */
    private static String toUpperCaseFirstOne(String s) {
        if (Character.isUpperCase(s.charAt(0)))
            return s;
        else
            return (new StringBuilder())
                    .append(Character.toUpperCase(s.charAt(0)))
                    .append(s.substring(1)).toString();
    }

}
